package controllers

import (
	"encoding/json"
	"go/pkg/app"
	"go/pkg/e"
	"go/services"

	"github.com/gin-gonic/gin"
)

func Login(c *gin.Context) {
	var m map[string]string
	b, _ := c.GetRawData()
	_ = json.Unmarshal(b, &m)
	username := m["username"]
	upassword := m["u_password"]

	err, userdata := services.Get_Users(username)
	if err != nil {
		app.Error(c,e.ERROR,err,"查无此用户")
		return
	}
	if userdata.Upassword != upassword {
		app.PswError(c,userdata,"密码错误")
		return
	}
	app.OK(c,userdata,"登录成功")
}
